<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>卡拉卡-在线选号平台</title>
		<link href="/css/style.css" rel="stylesheet" type="text/css" />
		<link href="/css/win.css" rel="stylesheet" type="text/css" />
		<link href="/css/pagination.css" rel="stylesheet" type="text/css" />
		<script type="text/javascript" src="../js/jquery-1.7.min.js"></script>
		<script type="text/javascript" src="../js/jquery.cookie.js"></script>
		<script type="text/javascript" src="../js/jquery.pagination.js"></script>
		<script type="text/javascript" src="../js/logon.js"></script>
		<script type="text/javascript" src="../js/jquery.blockUI.js"></script>
		<script type="text/javascript" src="../js/ajaxfileupload.js"></script>
		<script type="text/javascript" src="../js/jquery.dateFormat-1.0.js"></script>
		<script type="text/javascript" src="../js/datepicker/WdatePicker.js"></script>
		<script language="javascript" type="text/javascript">
			var page = 0; //页面索引初始值
			var pageSize = 9; //每页显示条数初始化，修改显示条数，修改这里即可
			$(function () {
				//initTable(10); //Load事件，初始化表格数据，页面索引为0（第一页）
				//分页，PageCount是总条目数，这是必选参数，其它参数都是可选
				$("#Pagination").pagination($!{model.get("count")}, {
					callback:PageCallback, //PageCallback() 为翻页调用次函数。
					prev_text:"上一页",
					next_text:"下一页",
					items_per_page:pageSize,
					num_edge_entries:2, //两侧首尾分页条目数
					num_display_entries:3, //连续分页主体部分分页条目数
					current_page:page, //当前页索引
				});
				//翻页调用
				function PageCallback(page,jq) {
					initTable(page);
				}
				//请求数据
				function initTable(page) {
					$.ajax({
						type:"POST",
						dataType:"text",
						url:"/operate/order/page", //提交到一般处理程序请求数据
						data:{page:page+1,pageSize:pageSize,aid:'$!{model.get("aid")}',status:'$!{model.get("status")}',st:'$!{model.get("st")}',et:'$!{model.get("et")}',keyword:'$!{model.get("keyword")}'}, //提交两个参数：pageIndex(页面索引)，pageSize(显示条数)
						success:function(data){
						//alert(data);
							$('#list-content').html('');
							$('#list-content').html(data);
							//$("#Result tr:gt(0)").remove();//移除Id为Result的表格里的行，从第二行开始（这里根据页面布局不同页变）
							//$("#Result").append(data); //将返回的数据追加到表格
						}
					});
				}
			});
			
			function search()
			{
				$("#searchForm").submit();
			}
			
			function hide()
			{
				$.unblockUI();
			}
			
			function detail(obj,pack)
			{
				$.ajax({    
			        type:'post',
			        url:'/order/detail',
			        data:{oid:obj},
			        cache:false,
			        async:false,
			        dataType:'json',
			        success:function(data){
			        	if(data=="error")
			        	{
			        		alert(data);
			        	}
			        	else
			        	{
			        		$("#oid").val(data.oid);
			        		$("#phonenum").val(data.phone);
			        		var orderTime = new Date();
			        		orderTime.setTime(data.order_time);
			        		var id_exp_date=new Date();
			        		id_exp_date.setTime(data.id_exp_date);
			        		$("#order_time").text($.format.date(orderTime,"yyyy/MM/dd HH:mm"));
			        		$("#storeName").text(data.name);
			        		$("#s_account").text(data.s_account);
			        		var ct=data.card_type==1?"芯1":data.card_type==2?"芯2":"其它";
			        		$("#phone").text(data.phone+"("+ct+")");
			        		var cn=data.carrier==1?"中国移动":data.carrier==2?"中国联通":"中国移动";
			        		var bra=data.brand==10?"全球通":data.brand==11?"动感地带":data.brand==12?"神州行":data.brand==20?"沃3G":data.brand==21?"如意通":data.brand==22?"特区行":data.brand==23?"新势力":"其它";
			        		$("#carrierName").text(cn+"("+bra+")");
			        		$("#package").text(pack);
			        		$("#tariff_type").text(data.tariff_type==1?"立即生效":data.tariff_type==2?"套餐减半":data.tariff_type==3?"下月生效":"无");
			        		$("#account_name").text(data.account_name);
			        		$("#id_exp_date").text($.format.date(id_exp_date,"yyyy/MM/dd"));
			        		$("#tel").text(data.tel);
			        		$("#id_number").text(data.id_number);
			        		$("#id_address").text(data.id_address);
			        		$("#c_address").text(data.c_address);
			        		if(data.status)
			        		{
			        			if(data.status==1)
			        			{
			        				$("#status").html("<span style=\"color:red\"><b>待开卡</b></span>");
			        				$("#active").css("display","");
			        			}
			        			else if(data.status==2)
			        			{
			        				$("#status").html("<span style=\"color:green\"><b>已开卡</b></span>");
			        				$("#active").attr("disabled","disabled");
			        				$("input[name=result][value=2]").attr("checked",true);
									$("#active").css("display","none");
			        			}
			        			else if(data.status==3)
			        			{
			        				$("#status").html("<span style=\"color:blue\"><b>已撤单</b></span>");
			        			}
			        			else if(data.status==4)
			        			{
			        				$("#status").html("<span style=\"color:red\"><b>已驳回</b></span>");
			        				$("input[name=result][value=4]").attr("checked",true);
			        				$("#active").css("display","none");
			        			}
			        		}
							$("#remark").val(data.remark);
							$("#iccid").text("订单详情");
							if(data.iccid && data.iccid != "")
							{
								$("#iccid").text("订单详情 (ICCID="+data.iccid+")");
							}
							$.blockUI({ message: $('#pop')});
			        	}
			        },
			        error: function(){  //失败
				        alert('Error loading document');
				    }
			    });  
			}
			
			function active()
			{
				var oid =$.trim($("#oid").val());
				var phone =$.trim($("#phonenum").val());
				var res =$("input[name='result']:checked").val();
				var remark = $.trim($("#remark").val());
				//alert(oid+",result="+res+",remark="+remark);
				if(res==4)
				{
					//alert(res);
					if(remark.length==0)
					{
						$("#remark").css("border","1px solid red");
						return;
					}
				}
				$.ajax({    
			        type:'post',
			        url:'/admin/order/active',
			        data:{oid:oid,status:res,phone:phone,remark:remark},
			        cache:false,
			        async:false,
			        dataType:'json',
			        success:function(data){
			        	if(data=="error")
			        	{
			        		alert(data);
			        	}
			        	else
			        	{
			        		if(res==2)
								alert("开卡完成！");
							if(res==4)
							{
								alert("订单已驳回！");
							}
							$('#searchForm').attr("action", "/operate/order");
							$("#searchForm").target="_self";
							$("#searchForm").submit();
			        	}
			        },
			        error: function(){  //失败
				        alert('Error loading document');
				    }
			    });
			}
			$(document).ready(function(){
				//var pop=new Pop("这里是标题，哈哈",
				//"http://www.yanue.info/js/pop/pop.html",
				//"请输入你的内容简介，这里是内容简介.请输入你的内容简介，这里是内容简介.请输入你的内容简介，这里是内容简介");
				
				function refu()
				{
					$.ajax({    
				        type:'post',
				        url:'/admin/notify',
				        data:{},
				        cache:false,
				        async:false,
				        dataType:'json',
				        success:function(data){
				        	if(data=="error")
				        	{
				        		alert(data);
				        	}
				        	else
				        	{
				        		if(data>0)
				        		{
				        			var pop = new Pop("新订单提醒","",data+"个新订单，请马上处理");
				        		}
				        	}
				        },
				        error: function(){  //失败
					        alert('Error loading document');
					    }
				    });
				}
				setInterval(refu,15000);//设置回调函数，3000毫秒回调一次  
			});
			
			//时间类型切换
			function doChange(obj)
			{
				$.ajax({    
			        type:'post',
			        url:'/common/datetype',
			        data:{dateType:obj.value},
			        cache:false,
			        async:false,
			        dataType:'json',
			        success:function(data){
			        	var d = jQuery.parseJSON(data);
			        	$("#st").val(data.st);
			        	$("#et").val(data.et);
			        },
			        error: function(){  //失败
				        alert('Error loading document');
				    }
			    });  
			}
		</script>
	</head>

	<body>
		<!--首先设置一个层:-->
		<div id="pop" class="pop" style="display:none">
			<div class="pop_body">
				<div class="pop_title" id="iccid">订单详情</div>
				<input type="hidden" id="oid" name="oid"/>
				<input type="hidden" id="phonenum" name="phonenum"/>
				<table width="100%" border="0" cellspacing="0" cellpadding="6" class="pop_table">
					<tr>
						<td width="18%" align="center" valign="top" class="line">定单时间：</td>
						<td class="line" id="order_time"></td>
						<td width="18%" class="line">门店：</td>
						<td class="line" id="storeName"></td>
					</tr>
					<tr>
						<td align="center" valign="top" class="line">工号：</td>
						<td class="line" id="s_account"></td>
						<td class="line">订购号码：</td>
						<td class="line" id="phone"></td>
					</tr>
					<tr>
						<td align="center" valign="top" class="line">运营商：</td>
						<td class="line" id="carrierName"></td>
						<td class="line">套餐内容：</td>
						<td class="line" id="package"></td>
					</tr>
					<tr>
						<td align="center" valign="top" class="line">当月资费方式：</td>
						<td class="line" id="tariff_type"></td>
						<td class="line">开户姓名：</td>
						<td class="line" id="account_name"></td>
					</tr>
					<tr>
						<td align="center" valign="top" class="line">证件号码：</td>
						<td class="line" id="id_number"></td>
						<td class="line">证件有效期：</td>
						<td class="line" id="id_exp_date"></td>
					</tr>
					<tr>
						<td align="center" valign="top" class="line">证件地址：</td>
						<td class="line" id="id_address"></td>
						<td class="line">联系电话：</td>
						<td class="line" id="tel"></td>
					</tr>
					<tr>
						<td align="center" valign="top" class="line">联系地址：</td>
						<td class="line" id="c_address"></td>
						<td class="line">状态：</td>
						<td class="line" id="status"></td>
					</tr>
					<tr>
						<td align="center" valign="top" class="line">操作结果</td>
						<td class="line"><input type="radio" name="result" value="2" checked/>开卡&nbsp;&nbsp;<input type="radio" name="result" value="4"/>驳回订单</td>
						<td class="line">处理意见：</td>
						<td class="line"><input type="text" id="remark" name="remark" style="border:#999 1px solid;" maxlength="128"/></td>
					</tr>

					<tr>
						<td colspan="4" align="center" class="td_n">
							<input type="button" id="active" name="Submit1" value="处理订单" class="login_btn" onclick="active();" />
							<input type="button" name="Submit" value="关闭" class="login_btn" onclick="hide();" />
						</td>
					</tr>
				</table>

			</div>
		</div>
		#include("header.html")
		<table width="100%" border="0" cellspacing="0" cellpadding="0" id="content">
			<tr><td valign="top" id="left">
			#include("menu_operate.html")
			</td>
			<td id="right">
				<div id="order">
					<form id="searchForm" name="searchForm" action="/operate/order" method="post">
					<div class="title">
						<span>首页 &gt; 订单管理</span>
					</div>
					<div class="step">
						代理商：
						<select name="aid">
							<option value="-1">全部</option>
							#foreach( $!{agent} in $!model.get("list") )
							<option value="$!{agent.aid}" #if($!{model.get("aid")}==$!{agent.aid}) selected #end>$!{agent.name}</option>
							#end
						</select>&nbsp;&nbsp;
						<select name="status">
							<option value="-1">全部</option>
							<option value="1" #if($!{model.get("status")}==1) selected #end>待开卡</option>
							<option value="2" #if($!{model.get("status")}==2) selected #end>已开卡</option>
							<option value="4" #if($!{model.get("status")}==4) selected #end>已驳回</option>
						</select>&nbsp;&nbsp;
						<select name="dateType" onChange="doChange(this);">
						  <option value="today" #if($!{model.get("dateType")}=="today") selected #end>今天</option>
						  <option value="yestday" #if($!{model.get("dateType")}=="yestday") selected #end>昨天</option>
						  <option value="week" #if($!{model.get("dateType")}=="week") selected #end>本周</option>
						  <option value="oneWeek" #if($!{model.get("dateType")}=="oneWeek") selected #end>一周内</option>
						  <option value="month" #if($!{model.get("dateType")}=="month") selected #end>本月</option>
						  <option value="oneMonth" #if($!{model.get("dateType")}=="oneMonth") selected #end>一月内</option>
						  <option value="period" #if($!{model.get("dateType")}=="period") selected #end>时间段</option>
						</select>
						<input type="text" id="st" name="st" value="$!{model.get("st")}" class="Wdate" style="height:20px" onfocus="WdatePicker();"/>-
						<input type="text" id="et" name="et" value="$!{model.get("et")}" class="Wdate" style="height:20px" onfocus="WdatePicker();"/>
						
						关键字：
						<input type="text" name="keyword" class="sou_input" value="$!{model.get("keyword")}"/>
						<input type="button" name="Submit" value="查询" class="out_btn" onclick="search();" />
					</div>
					</form>
				</div>
				<div id="list">
					<div class="title" style="font-size:13px;font-weight:600;display:none">
						<span>查询结果</span>
					</div>
					<div class="data">
						<table width="100%" border="0" cellspacing="0" cellpadding="0">
							<thead>
							<tr>
								<td width="110">订单时间</td>
								<td width="120">门店</td>
								<td width="30">工号</td>
								<td width="100">手机号码</td>
								<td width="110">套餐月费</td>
								<td width="40">价格</td>
								<td width="40">预存</td>
								<td width="40">折扣</td>
								<td width="40">状态</td>
								<td width="50">支付</td>
								<td>处理意见</td>
								<td width="70" align="center">操作</td>
							</tr>
							</thead>
							<tbody id="list-content">
							</tbody>
							<tr>
								<td colspan="12">
									<table width="100%" border="0" cellspacing="0" cellpadding="0">
										<tr>
											<td><div id="Pagination" class="pagination" style="margin:4px 0 0 0"></div></td>
											<td width="80">共$!{model.get("count")}条</td>
										</tr>
									</table>
								</td>
							</tr>
						</table>
					</div>
				</div>
				</td></tr></table>
		#include("footer.html")
		#include("lowerpop.html")
	</body>
</html>
